"""用户个人信息页面"""
from page.base_page import BasePage
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
class UserInfoPage(BasePage):
    #用户名定位器
    name_locator = (By.NAME, 'name')
    #邮箱的定位器
    email_locator=(By.NAME,"email")
    #手机的定位器
    telephone_locator=(By.NAME,"telephone")
    #保存的定位器
    btn_save_locator=(By.CSS_SELECTOR,
                          "body > div.container > div.row > div:nth-child(2) > form > table > thead > tr > td:nth-child(2) > input.btn.btn-primary")
    # 用户类别的定位器
    category_id_locator = (By.ID, 'category_id')
    #修改成功定位器
    success_update_locator = (By.CSS_SELECTOR,  'body > div.container > div.row > div:nth-child(1) > div')

    url='/crm5/index.php?m=user&a=edit'

    def input_name(self,name):
        # 输入用户名
        self.driver.find_element(*self.name_locator).clear()
        self.driver.find_element(*self.name_locator).send_keys(name)
    def input_email(self,email):
        """输入邮箱"""
        self.driver.find_element(*self.email_locator).clear()
        self.driver.find_element(*self.email_locator).send_keys(email)
    def input_telephone(self,telephone):
        """输入手机号"""
        self.driver.find_element(*self.telephone_locator).clear()
        self.driver.find_element(*self.telephone_locator).send_keys(telephone)
    def click_save(self):
        #点击保存
        self.driver.find_element(*self.btn_save_locator).click()
    def choose_category(self,category=0):
        """选择用户类别"""
        # 找到下拉框
        category_element = self.driver.find_element(*self.category_id_locator)
        # 实例化Select
        category_obj = Select(category_element)
        # 找第一个元素
        category_obj.select_by_index(category)  # 通过索引取值
    def get_success_text(self):
        """获取修改成功信息"""
        return self.driver.find_element(*self.success_update_locator).text